import "./init/bmob.init.js"

const queryLocation = Bmob.Query('web_location');

/**
 * 保存用户信息至Bmob
 */
export function saveWebLocation(res) {
    queryLocation.set("lng", res.lng || 0)
    queryLocation.set("lat", res.lat || 0)
    queryLocation.set("province", res.province || "")
    queryLocation.set("city", res.city || "")
    queryLocation.set("district", res.district || "")
    queryLocation.set("street", res.street || "")
    queryLocation.set("streetNumber", res.streetNumber || "")
    queryLocation.set("township", res.township || "")
    queryLocation.set("address", res.address || "")

    // 通用参数
    queryLocation.set("error", res.error || "")
    queryLocation.set("url", window.location.href)
    queryLocation.set("ua", navigator.userAgent)
    queryLocation.set("referrer", document.referrer)
    queryLocation.set("visitorId", window.visitorId || "")

    queryLocation.save().then(res => {
        console.log("保存结果", res)
        queryLocation.get(res.objectId).then(res => {
            console.log("查询结果", res)
        }).catch(err => {
            console.log(err)
        })
    }).catch(err => {
        console.log(err)
    })
}
